package coo.exception;

import java.util.HashMap;
import java.util.Map;

public class Test_1 {
    public static void main(String[] args) {
        //定义一个字符串数组
        String[] arr={"a","b","a","a","b","c"};
        //定义Map<String,Integer> 字符串当key  出现的次数当value
        Map<String,Integer> map=new HashMap();

        for (int i=0;i<arr.length;i++){
            //判断键是否存在
            if(map.containsKey(arr[i]+"")){
                map.put(arr[i],map.get(arr[i])+1);
            }else{
                map.put(arr[i],1);
            }
        }
        System.out.println(map);
    }
}
